package com.bestow.basic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.basic.domain.CshBankAccount;
import com.bestow.basic.service.ICshBankAccountService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 银行支行Controller
 * 
 * @author liliu
 * @date 2022-09-26
 */
@RestController
@RequestMapping("/basic/bankAccount")
public class CshBankAccountController extends BaseController
{
    @Autowired
    private ICshBankAccountService cshBankAccountService;

    /**
     * 查询银行支行列表
     */
    @PreAuthorize("@ss.hasPermi('basic:bankAccount:list')")
    @GetMapping("/list")
    public TableDataInfo list(CshBankAccount cshBankAccount)
    {
        startPage();
        List<CshBankAccount> list = cshBankAccountService.selectCshBankAccountList(cshBankAccount);
        return getDataTable(list);
    }

    /**
     * 导出银行支行列表
     */
    @PreAuthorize("@ss.hasPermi('basic:bankAccount:export')")
    @Log(title = "银行支行", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CshBankAccount cshBankAccount)
    {
        List<CshBankAccount> list = cshBankAccountService.selectCshBankAccountList(cshBankAccount);
        ExcelUtil<CshBankAccount> util = new ExcelUtil<CshBankAccount>(CshBankAccount.class);
        util.exportExcel(response, list, "银行支行数据");
    }

    /**
     * 获取银行支行详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:bankAccount:query')")
    @GetMapping(value = "/{bankAccountId}")
    public AjaxResult getInfo(@PathVariable("bankAccountId") Long bankAccountId)
    {
        return AjaxResult.success(cshBankAccountService.selectCshBankAccountByBankAccountId(bankAccountId));
    }

    /**
     * 新增银行支行
     */
    @PreAuthorize("@ss.hasPermi('basic:bankAccount:add')")
    @Log(title = "银行支行", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CshBankAccount cshBankAccount)
    {
        return toAjax(cshBankAccountService.insertCshBankAccount(cshBankAccount));
    }

    /**
     * 修改银行支行
     */
    @PreAuthorize("@ss.hasPermi('basic:bankAccount:edit')")
    @Log(title = "银行支行", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CshBankAccount cshBankAccount)
    {
        return toAjax(cshBankAccountService.updateCshBankAccount(cshBankAccount));
    }

    /**
     * 删除银行支行
     */
    @PreAuthorize("@ss.hasPermi('basic:bankAccount:remove')")
    @Log(title = "银行支行", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bankAccountIds}")
    public AjaxResult remove(@PathVariable Long[] bankAccountIds)
    {
        return toAjax(cshBankAccountService.deleteCshBankAccountByBankAccountIds(bankAccountIds));
    }
}
